<?php

class Form {

    // <editor-fold defaultstate="collapsed" desc="Champs">
    private $_id = "inconnue";
    private $_action = "";
    private $_method = "POST";
    
    private $_textHTML = "";

    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Propriété">
    public function __get($propriete) {
        switch ($propriete) {
            case "id": return $this->_id;
                break;
            case "action": return $this->_action;
                break;
            case "method": return $this->_method;
                break;
            case "textHTML": return $this->_textHTML;
                break;
        }
    }
    public function __set($propriete,$value) {
        switch ($propriete) {
            case "id":$this->_id = $value;
                break;
            case "action":$this->_action = $value;
                break;
            case "method":$this->_method = $value;
                break;
            case "textHTML":$this->_textHTML= $value;
                break;
        }
    }

    //</editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Constructeur">
    public function __construct($id,$action,$method,$texteTitre=null)
    {
        $this->id = $id;
        $this->action = $action;
        $this ->method = $method;
        
        $divTitre =($texteTitre==null)?"":"<div class='titre'>$texteTitre</div>";
        
        $this->textHTML.= "<form id='$id' action='$action' method='$method'></ br>$divTitre</ br>";
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Methodes">
    public function __tostring(){
        return $this->textHTML .'</form>';
    }
    
    public function beginFieldset($textLegend=null,$class=null){
        $legend = ($textLegend==null)?"":"<legend> $textLegend : </legend>";
        $this->textHTML.= "<fieldset class='" .$class ."'>" .$legend;
    }
    public function endFieldset(){
        $this->textHTML.="</fieldset>";
    }
    Public function addInput($text,$name,$id,$type,$style=null){
        $this->textHTML.="<label for='" .$name . "'>" .$text . ":</label><input type='" . $type . "' name='" .$name . "' id='" .$id ."' style='" . $style . "' /></br>";
    }
    Public function addInputCheckBox($for,$class,$text,$name,$value,$id,$type,$checked=null){
        $this->textHTML.="<label for='" .$for . "' class='" . $class . "'>" .$text ." </label> <input type='" . $type ."' name= '" .$name ."' value = '" .$value ."' id='" . $id ."' checked='" .$checked ."' />";
    }
    Public function span($text=null){
        $this->textHTML.="<span>". $text ."</span>";
    }
    Public function addSubmit($type,$name,$id,$value){
        $this->textHTML.="<input type='" . $type . "' name='" . $name . "' id='" . $id . "' value='" . $value . "' />";
    }
            

    // </editor-fold>
}

?>